#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
int n;
int a[200009];
int dfs(int pr,int pb,int ans,int i){
    if(i==n) return ans;
    int res=0;
    if(a[i+1]==a[pr]) res=max(res,dfs(i+1,pb,ans+a[pr],i+1));
    else res=max(res,dfs(i+1,pb,ans,i+1));
    if(a[i+1]==a[pb]) res=max(res,dfs(pr,i+1,ans+a[pb],i+1));
    else res=max(res,dfs(pr,i+1,ans,i+1));
    return res;

}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        cin>>n;
        for(int i=1;i<=n;++i){
            cin>>a[i];
        }
        cout<<dfs(0,0,0,0)<<"\n";
    }
    return 0;
}
